<?php
use yii\helpers\Url;
use yii\web\View;
// use yii\Web\View;
use app\assets\NewCreativeAsset;
NewCreativeAsset::register($this);
$this->title = $this->context->pageTitle.Yii::$app->params['titleSuffix'];
$this->params['breadcrumbs'] = [
  [
    'label' => '创意管理',
    'url' => ['creative-list']
  ],
  '编辑悬浮创意'
];
?>
<div class="page-header">
  <h1>
    创意管理
    <small>编辑悬浮创意</small>
  </h1>
</div>
<div class="panel panel-default">
  <div class="panel-heading">
    <i class="fa fa-edit"></i>
    编辑视频创意
    <ul class="list-unstyled pull-right">
      <li>
        <a href="#">
          <i class="fa fa-chevron-up"></i>
        </a>
      </li>
    </ul>
  </div>
  <div class="panel-body">
    <div class="row">
      <div class="col-sm-8 col-sm-offset-2">
        <form class="form-horizontal" id="data-frm" method="POST" action="<?php echo Url::to(['creative/new-overlay-creative-handle']);?>">
          <input class="hidden" type="text" name="id" value="<?=$creative['id']?>">
          <fieldset>
            <legend>创意信息</legend>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="creative_name" >
                <em>*</em>
                创意名称：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="creative_name" type="text" name="name" value="" placeholder="创意名称">
                <div class="help-block text-error" id="creative_name_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="creative_vocation_large" >
                <em>*</em>
                创意行业：
              </label>
              <div class="col-sm-4">
                <select class="form-control" id="creative_vocation_large" name="parent_category">
                </select>
              </div>
              <div class="col-md-4">
                <select class="form-control" id="creative_vocation_small" name="category">
                </select>
              </div>
            </div>
<!--             <div class="form-group">
              <label class="col-sm-2 control-label" for="advertiser_name" >
                广告主名称：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="advertiser_name" type="text" name="advertiser_name" value="" placeholder="广告主名称">
                <div class="help-block text-error" id="advertiser_name_err"></div>
              </div>
            </div> -->
            <div class="form-group">
              <label class="col-sm-2 control-label" for="landing_page_url">
                <em>*</em>
                目标地址：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="landing_page_url" type="text" name="landing_page" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="landing_page_url_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="audit_target_url">
                审核用目标地址：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="audit_target_url" type="text" name="adomain" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="audit_target_url_err"></div>
              </div>
            </div>
<!--             <div class="form-group">
              <label class="col-sm-2 control-label" for="landing_page_main_url">
                落地页主域名：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="landing_page_main_url" type="text" name="adomain" value="" placeholder="请填写一级域名或者二级域名。">
                <div class="help-block text-error" id="landing_page_main_url_err"></div>
                <p class="help-block">提示：如果网站URL是http://www.baidu.com，只需填写baidu.com；如果网站URL是http://www.sina.com.cn，只需填写sina.com.cn。</p>
              </div>
            </div> -->
            <div class="form-group">
              <label class="col-sm-2 control-label" for="impr_monitor_url">
                第三方曝光监测：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="impr_monitor_url" type="text" name="show_monitor_url" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="impr_monitor_url_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="click_monitor_url" >
                第三方点击监测：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="click_monitor_url" type="text" name="click_monitor_url" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="click_monitor_url_err"></div>
              </div>
            </div>      
            <div class="form-group">
        <label for="creative_title" class="col-sm-2 control-label">
                创意标题：
        </label>
              <div class="col-sm-10">
                <input class="form-control" id="creative_title" name="creative_title" type="text" value="">
              </div>
            </div>
            <div class="form-group">
        <label for="creative_description" class="col-sm-2 control-label">
                创意详细描述：
        </label>
              <div class="col-sm-10">
                 <input class="form-control" id="creative_description" name="creative_description" type="text" value="">
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="alternative_creative_size">
                有效素材尺寸：
              </label>
              <div class="col-sm-10">
                <p class="form-control-static" id="alternative_creative_size" name="alternative_creative_size"><?php 
        $sizeList = [];
        foreach ($vsizes as $k => $size) {
          $sizeList[] = $size['width'].'*'.$size['height'];
        }
        $sizeList = array_unique($sizeList);
        sort($sizeList);
        foreach ($sizeList as $k => $size) {
          echo $size.',  ';
          if(($k+1)%9 == 0) echo '</br>';
        }
        ?></p>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="alternative_creative_size">
                有效素材格式：
              </label>
              <div class="col-sm-10">
                <p class="form-control-static" id="alternative_creative_size" name="alternative_creative_size">JPG,PNG</p>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="upload_material">
                <em>*</em>
                上传素材：
              </label>
              <div class="col-sm-2 col-sm-offset-8">
                <button class="btn btn-info" id="upload-material" type="button">
                  <i class="fa fa-upload"></i>
                  上传
                </button>
              </div>
              <div class="col-sm-12 mt10 text-center">
                <div class="creative-preview">

                </div>
                <img class="img-thumbnail creative_material_default" id="creative_material_default" data-src="holder.js/310x260/text:未上传" alt="未上传">
                <input id="upload_material" name="upload_material" type="hidden" value="<?= $material['id']?>">
                <input type="hidden" class="creative-id" value="<?=$creative['id']?>">
                <input type="hidden" class="creative-width" value="<?=$material['width']?>" >
                <input type="hidden" class="creative-height" value="<?=$material['height']?>" >
                <?php
                    switch ($creative['format_id']) {
					  case 1:
						  $type = 'jpg';
                          break;
					  case 2:
						  $type = 'png';
                          break;
                      case 3:
                          $type = 'swf';
                          break;
                      case 5:
                          $type = 'flv';
                          break;
                      case 6:
                          $type = 'mp4';
                          break;
                      default:
                          $type = 'flv';
                          break;
                    }
                    $preview = <<<FINE
                    <input type="hidden" class="creative-type" name="type" value="$type" >
FINE;
                echo $preview;
                ?>
                <input type="hidden" class="creative-url" name="url" value="<?=$videoUrl?>">
                <div id="creative-preview-details"></div>
                <div class="help-block text-error" id="upload_material_err"></div>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <div class="btn-form-group pull-right">
                  <input class="operate-type" type="hidden" name="operate_type" value="save">
                  <button type="submit" class="btn btn-primary" data-loading-text="<i class='fa fa-spinner fa-spin'></i> 数据提交中...">保存</button>
                  <a href="<?php echo Url::to(['creative/creative-list']); ?>" class="btn btn-default">返回列表</a>
                </div>
              </div>
            </div>
          </fieldset>
        </form>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="upload-material-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title">上传素材</h4>
      </div>
      <div class="modal-body">
        <div class="portlet-content">
          <span class="btn btn-success btn-sm fileinput-button">
            <i class="fa fa-plus"></i>
            <span>选择文件</span>
            <input id="creative-id" type="hidden" name="creative_id" value="${id}" >
            <!-- The file input field used as target for the file upload widget -->
            <input type="file" multiple="" name="files[]" id="fileupload">
          </span>
          <br>
          <br>
          <!-- The global progress bar -->
          <div class="progress" id="progress">
              <div aria-valuemax="100" aria-valuemin="0" class="progress-bar progress-bar-success progress-bar-striped">0%</div>
          </div>
          <!-- The container for the uploaded files -->
          <div class="files" id="files">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>ID</th>
                  <th>文件名称</th>
                  <th>文件大小(KB)</th>
                  <th>上传时间</th>
                  <th>判断信息</th>
                  <th>上传者</th>
                </tr>
              </thead>
              <tbody></tbody>
              </table>
            </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" id="upload-confirm-operate" data-material-id="">确定</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
  // $uploadMaterialUrl = Url::to(['creative/upload-video']);
  $uploadMaterialUrl =  Url::to(['creative/upload-overlay']);
  $videoPluginUrl = Yii::getAlias('@web/').Yii::$app->params['envDir'].'/js/vendor/flowplayer/flowplayer.swf';
  $creativeVocation = $categories;
  $this->registerJs("VAM.setVar('UPLOAD_MATERIAL_URL','$uploadMaterialUrl');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('VIDEO_PLUGIN_URL','$videoPluginUrl');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('CREATIVE_VOCATION','$creativeVocation')", View::POS_HEAD);

  $parentCategory = array_shift($category);
  $childCategory = array_shift($category);
  $this->registerJs("VAM.setVar('parent_category','$parentCategory')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('child_category','$childCategory')", View::POS_HEAD);
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/creative/newAppCreative.js"]);
  });
</script>